<?php
include_once("connect.php");
include_once ("log_order.php"); //test!

$order_id=$_GET['id'];

$sql = "SELECT * FROM order_list WHERE id=$order_id";
$rs = mysql_query($sql);
if ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {

	$package_name=$row['package_name'];
	$package_weight=$row['package_weight'];
	$package_length=$row['package_length'];
	$package_width=$row['package_width'];
	$package_height=$row['package_height'];
	
	$item1_id = $row['item1_id'];
	$item2_id = $row['item2_id'];
	$item3_id = $row['item3_id'];
	
	$user_id = $row['order_user_id'];
	//$order_upadate_time = $row['update_time'];
	
	//----
	$item_s1=$_GET['s1'];
	if(!empty($item_s1) && $item_s1>0){	
		$item1_id = $item_s1;
	}
	
	$item_s2=$_GET['s2'];
	if(!empty($item_s2) && $item_s2>0){	
		$item2_id = $item_s2;
	}
	
	$item_s3=$_GET['s3'];
	if(!empty($item_s3) && $item_s3>0){	
		$item3_id = $item_s3;
	}
	
	//----
	
	$item_name1 = '';
	$item_madein1 = '';
	$item_amount1 = '';
	$item_pre_weight1 = '';
	$item_pre_price1 = '';
	$item_weight1 = '';
	$item_price1 = '';	
	if($item1_id>0){
		$sql = "SELECT * FROM order_item WHERE id=$item1_id";	
		$rs = mysql_query($sql);
		if ($row1 = mysql_fetch_array($rs, MYSQL_ASSOC)) {			
			$item_name1 = $row1['item_name'];
			$item_madein1 = $row1['item_madein'];
			$item_amount1 = $row1['item_amount'];
			$item_pre_weight1 = $row1['item_pre_weight'];
			$item_pre_price1 = $row1['item_pre_price'];
			$item_weight1 = $row1['item_weight'];
			$item_price1 = $row1['item_price'];			
		} 	
	}

	$item_name2 = '';
	$item_madein2 = '';
	$item_amount2 = '';
	$item_pre_weight2 = '';
	$item_pre_price2 = '';
	$item_weight2 = '';
	$item_price2 = '';	
	if($item2_id>0){
		$sql = "SELECT * FROM order_item WHERE id=$item2_id";	
		$rs = mysql_query($sql);
		if ($row2 = mysql_fetch_array($rs, MYSQL_ASSOC)) {			
			$item_name2 = $row2['item_name'];
			$item_madein2 = $row2['item_madein'];
			$item_amount2 = $row2['item_amount'];
			$item_pre_weight2 = $row2['item_pre_weight'];
			$item_pre_price2 = $row2['item_pre_price'];
			$item_weight2 = $row2['item_weight'];
			$item_price2 = $row2['item_price'];			
		} 	
	}
	
	$item_name3 = '';
	$item_madein3 = '';
	$item_amount3 = '';
	$item_pre_weight3 = '';
	$item_pre_price3 = '';
	$item_weight3 = '';
	$item_price3 = '';	
	if($item3_id>0){
		$sql = "SELECT * FROM order_item WHERE id=$item3_id";	
		$rs = mysql_query($sql);
		if ($row3 = mysql_fetch_array($rs, MYSQL_ASSOC)) {			
			$item_name3 = $row3['item_name'];
			$item_madein3 = $row3['item_madein'];
			$item_amount3 = $row3['item_amount'];
			$item_pre_weight3 = $row3['item_pre_weight'];
			$item_pre_price3 = $row3['item_pre_price'];
			$item_weight3 = $row3['item_weight'];
			$item_price3 = $row3['item_price'];			
		} 	
	}

} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="hello" />
<meta name="description" content="Hello" />
<title>order_item</title>

<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/fancybox.css" />

<script src="js/jquery.js" type="text/javascript"></script>

<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.fancybox.js" type="text/javascript"></script>
<script src="js/jquery.message.js" type="text/javascript"></script>

<style type="text/css">
table{width:100%; margin:20px auto; border-collapse:collapse;}
table td{line-height:24px; padding:2px; padding-left:8px; border:1px solid #b6d6e6;}
.table_title{height:26px; line-height:26px; background:url(css/btn_bg.gif) repeat-x bottom; font-weight:bold; text-indent:.3em; outline:0;}
.table_label2{background:#e8f5fe; text-align:center; font-weight:bold;}
.table_label{background:#e8f5fe; text-align:right; }

.table_line{ text-align:center; font-weight:bold;}

.btn{height:24px; background:url(css/btn_bg.gif) repeat-x; padding:0 4px; font-size:12px; border:1px solid #ccc; cursor:pointer; margin-left:3px}
.input{border:1px solid #369; background:#ffc; padding:2px}
.msg{padding-left:30px; margin-top:20px}
textarea{font-size:12px}
</style>

<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">

/* $.validator.setDefaults({　　　 
　　 submitHandler: function(edit_form) {　 
　　　　 //edit_form.submit();　 
　 }　　　 
});  */


/* $(document).ready(function() {
 　 $("#edit_form").validate( {
		rules : {
			package_weight : "required",
			package_name   :  { required: true, email: true }
		},
		messages : {
		　　 package_weight :"请输入总重!!!"
		} 
　 }); 
}); */



$(function(){
	$('#edit_form').ajaxForm({
		beforeSubmit: validate,
		success: function(msg){
			if(msg>'10000'){		
				$().message("修改成功");				
			}else{
				alert(msg);
			}
			self.location='order_list.php';
		}
	});

	$("#cancle_btn").click(function(){
		//window.history.back(-1); 
		self.location='order_list.php';
	});
	
	$("#save_item_btn").click(function(){
		self.location='order_save_item.php?id=<?php echo $order_id; ?>';
	});

});

function validate(formData, jqForm, options) { 
	for (var i=0; i < 5; i++) { 
        if (!formData[i].value) { 
			$().message("请输入完整的 包裹 信息");
            return false; 
        } 
    } 
	//---判断是否是数值:
	var array1 = ["package_weight","package_length","package_width","package_height"];
	var array2 = ["包裹总重(公斤)","包裹长(厘米)","包裹宽(厘米)","包裹高(厘米)"];	
	//alert( array1);
	//alert( array2);	
	for (var i=0; i < array1.length; i++) { 		
		var ivalue = document.getElementById( array1[i] ).value;
		//alert( ivalue );		
        if ( !if_num(ivalue) ) { 
			alert( array2[i] +" 必须为数值,请重新输入");
			document.getElementById( array1[i] ).focus();
            return false; 
        } 	
    }
	
	
	for (var i=5; i < formData.length; i++) { 
        if (!formData[i].value) { 
			$().message("请输入完整的 物品1 信息");
            return false; 
        } 
		i++;
		i++;
    }
	//---判断是否是数值:
	var array1 = ["item_amount1", "item_pre_weight1", "item_pre_price1", "item_weight1", "item_price1"];
	var array2 = ["物品1数量","物品1单位净重(公斤)","物品1单价(欧元)","物品1总重(公斤)","物品1总价(欧元)"];	
	//alert( array1);
	//alert( array2);	
	for (var i=0; i < array1.length; i++) { 		
		var ivalue = document.getElementById( array1[i] ).value;
		//alert( ivalue );		
        if ( !if_num(ivalue) ) { 
			alert( array2[i] +" 必须为数值,请重新输入");
			document.getElementById( array1[i] ).focus();
            return false; 
        } 	
    }
	
	
	
 	
	var tag2=0;
	for (var i=6; i < 26; i++) { 
        if (formData[i].value) { 
			tag2=1;
			break;
        } 
		i++;
		i++;
    } 
	if(tag2==1){
		for (var i=6; i < 26; i++) { 
			if (!formData[i].value) { 
				$().message("物品2为选填,要么填完整,要么清空");
				return false; 
			} 
			i++;
			i++;
		}
		//---判断是否是数值:
		var array1 = ["item_amount2", "item_pre_weight2", "item_pre_price2", "item_weight2", "item_price2"];
		var array2 = ["物品2数量","物品2单位净重(公斤)","物品2单价(欧元)","物品2总重(公斤)","物品2总价(欧元)"];	
		for (var i=0; i < array1.length; i++) { 		
			var ivalue = document.getElementById( array1[i] ).value;
			if ( !if_num(ivalue) ) { 
				alert( array2[i] +" 必须为数值,请重新输入");
				document.getElementById( array1[i] ).focus();
				return false; 
			} 	
		}
	}
	
	
	var tag3=0;
	for (var i=7; i < 26; i++) { 
        if (formData[i].value) { 
			tag3=1;
			break;
        } 
		i++;
		i++;
    } 
	if(tag3==1){
		for (var i=7; i < 26; i++) { 
			if (!formData[i].value) { 
				$().message("物品3为选填,要么填完整,要么清空");
				return false; 
			} 
			i++;
			i++;
		} 
		//---判断是否是数值:
		var array1 = ["item_amount3", "item_pre_weight3", "item_pre_price3", "item_weight3", "item_price3"];
		var array2 = ["物品3数量","物品3单位净重(公斤)","物品3单价(欧元)","物品3总重(公斤)","物品3总价(欧元)"];	
		for (var i=0; i < array1.length; i++) { 		
			var ivalue = document.getElementById( array1[i] ).value;
			if ( !if_num(ivalue) ) { 
				alert( array2[i] +" 必须为数值,请重新输入");
				document.getElementById( array1[i] ).focus();
				return false; 
			} 	
		}
	}
	
	$().message("正在提交...");
}


//-------------判断是否为数值, 
function if_num(value){
	var reg=/^[1-9]\d*$|^0$/;   // 注意：故意限制了 0321 这种格式，如不需要，直接reg=/^\d+$/;
	//var reg = /^\d+(\.\d+)?$/;   // 小数也算数值
	if(reg.test(value)==true){
		//alert("都是数字！通过");
		return true;
	}else{
		//alert("不是纯数字！失败！");
		return false;
	}
}

</script>
</head>

<body>

<div id="main">

<form id="edit_form" action="order_do_item.php?action=edit" method="post">
  
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <thead>
    <tr class="table_title">
      <td colspan="6"><?php 
	  if($item1_id > 0){
		echo "修改-订单号:".$order_id; 
	  }else{
		echo "新增订单:".$order_id; 
	  }
	  ?></td>
    </tr>
  </thead>
  <tbody>
		
	<tr>
      <td class="table_line" id="shipper" colspan="6" alight=center>包裹信息</td>
    </tr>   
	<tr>
      <td class="table_label"  colspan="3" width="50%">包裹总重(公斤)：</td>
	  <td class="eidt"  colspan="3">
		<input type="text" class="input1" id="package_weight" name="package_weight" required value="<?php echo $package_weight; ?>" />
	  </td>
    </tr>
	<tr>
      <td class="table_label"  colspan="3" width="50%">包裹长(厘米)：</td>
	  <td class="eidt"  colspan="3">
		<input type="text" class="input1" id="package_length" name="package_length" value="<?php echo $package_length; ?>" />
	  </td>
    </tr>
	<tr>
      <td class="table_label"  colspan="3" width="50%">包裹宽(厘米)：</td>
	  <td class="eidt"  colspan="3">
		<input type="text" class="input1" id="package_width" name="package_width"  value="<?php echo $package_width; ?>" />
	  </td>
    </tr>
	<tr>
      <td class="table_label"  colspan="3" width="50%">包裹高(厘米)：</td>
	  <td class="eidt"  colspan="3">
		<input type="text" class="input1" id="package_height" name="package_height"  value="<?php echo $package_height; ?>" />
	  </td>
    </tr>
	<tr>
      <td class="table_label"  colspan="3" width="50%">物品名称：</td>
	  <td class="eidt"  colspan="3">
		<input type="text" class="input1" id="package_name" name="package_name" value="<?php echo $package_name; ?>" />
	  </td>
    </tr>
	
	<tr>
      <td class="table_line" id="shipper" colspan="6" alight=center>&nbsp</td>
    </tr>  
	<tr>
      <td class="table_label2"  colspan="2" width="33%">物品1信息(必填)</td>
	  <td class="table_label2"  colspan="2" width="33%">物品2信息(选填)</td>
	  <td class="table_label2"  colspan="2" width="33%">物品3信息(选填)</td>
    </tr>	
	<tr>
      <td class="table_label" width="14%">物品1名称：</td>
      <td class="edit"  width="19%" >
		<input type="text" class="input1" id="item_name1" name="item_name1"  value="<?php echo $item_name1; ?>" />
	  </td>	  
	  <td class="table_label" width="14%">物品2名称：</td>
      <td class="edit"  width="19%" >
		<input type="text" class="input1" id="item_name2" name="item_name2"  value="<?php echo $item_name2; ?>" />
	  </td>
	  <td class="table_label" width="14%">物品3名称：</td>
      <td class="edit"  width="19%" >
		<input type="text" class="input1" id="item_name3" name="item_name3"  value="<?php echo $item_name3; ?>" />
	  </td>
    </tr>
	
	<tr>
      <td class="table_label">物品1数量：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_amount1" name="item_amount1"  value="<?php echo $item_amount1; ?>" />
	  </td>	  
	  <td class="table_label">物品2数量：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_amount2" name="item_amount2"  value="<?php echo $item_amount2; ?>" />
	  </td>	
	  <td class="table_label">物品3数量：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_amount3" name="item_amount3"  value="<?php echo $item_amount3; ?>" />
	  </td>	
    </tr>		
	
	<tr>
      <td class="table_label">物品1单位净重(公斤)</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_weight1" name="item_pre_weight1"  value="<?php echo $item_pre_weight1; ?>" />
	  </td>	  
	  <td class="table_label">物品2单位净重(公斤)</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_weight2" name="item_pre_weight2"  value="<?php echo $item_pre_weight2; ?>" />
	  </td>	
	  <td class="table_label">物品3单位净重(公斤)</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_weight3" name="item_pre_weight3"  value="<?php echo $item_pre_weight3; ?>" />
	  </td>	
    </tr>		

	<tr>
      <td class="table_label">物品1原产地：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_madein1" name="item_madein1"  value="<?php echo $item_madein1; ?>" />
	  </td>	  
	  <td class="table_label">物品2原产地：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_madein2" name="item_madein2"  value="<?php echo $item_madein2; ?>" />
	  </td>	
	  <td class="table_label">物品3原产地：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_madein3" name="item_madein3"  value="<?php echo $item_madein3; ?>" />
	  </td>	
    </tr>		
	
	<tr>
      <td class="table_label">物品1单价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_price1" name="item_pre_price1"  value="<?php echo $item_pre_price1; ?>" />
	  </td>	  
	  <td class="table_label">物品2单价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_price2" name="item_pre_price2"  value="<?php echo $item_pre_price2; ?>" />
	  </td>	
	  <td class="table_label">物品3单价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_pre_price3" name="item_pre_price3"  value="<?php echo $item_pre_price3; ?>" />
	  </td>	
    </tr>

	<tr>
      <td class="table_label">物品1总价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_price1" name="item_price1"  value="<?php echo $item_price1; ?>" />
	  </td>	  
	  <td class="table_label">物品2总价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_price2" name="item_price2"  value="<?php echo $item_price2; ?>" />
	  </td>	
	  <td class="table_label">物品3总价(欧元)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_price3" name="item_price3"  value="<?php echo $item_price3; ?>" />
	  </td>	
    </tr>

	<tr>
      <td class="table_label">物品1总重(公斤)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_weight1" name="item_weight1"  value="<?php echo $item_weight1; ?>" />
	  </td>	  
	  <td class="table_label">物品2总重(公斤)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_weight2" name="item_weight2"  value="<?php echo $item_weight2; ?>" />
	  </td>	
	  <td class="table_label">物品3总重(公斤)：</td>
      <td class="edit" >
		<input type="text" class="input1" id="item_weight3" name="item_weight3"  value="<?php echo $item_weight3; ?>" />
	  </td>	
    </tr>		
	
	<tr>
      <td class="table_line"  colspan="6" alight=center>
	  <input type="hidden" class="input2" name="order_id"  value="<?php echo $order_id; ?>" />
	  <input type="hidden" class="input2" name="user_id"  value="<?php echo $user_id; ?>" />
	  
	  <input type="submit" class="btn" value="提 交"/>	&nbsp; &nbsp;  
	  <input type="button" class="btn" id="cancle_btn" value="返 回" /> &nbsp; &nbsp;
	  <input type="button" class="btn" id="save_item_btn" value="常用物品" /> &nbsp; &nbsp;
	  </td>
    </tr> 
	
  </tbody>
</table>
</form>
<br />

</div>

</body>
</body>
</html>